/**
 * @param {number[]} nums
 * @return {number}
 */
var maxSumDivThree = function (nums) {
  let arr=[]
  function bc(index,cur){
    if(cur!=0 &&cur%3==0){
      arr.push(cur)
    }

    for(let i=index;i<nums.length;i++){
      if(nums[i]%3==0){
        cur+=nums[i]
        continue
      }
      cur+=nums[i]
      bc(i+1,cur)
      cur-=nums[i]
    }
  }

  bc(0,0)
  return Math.max(...arr)

};
maxSumDivThree([3,6,5,1,8])